import { defineStore } from 'pinia'
import { ref } from 'vue'
import CommonModel from '@/model/common'

const useCommonStore = defineStore('commonStore', () => {
  const activeList = [
    { label: '启用', value: 1 },
    { label: '停用', value: 2 }
  ]

  const storeStausList = [
    { label: '申请开店', value: 'opening' },
    { label: '开店成功', value: 'open_finished' },
    { label: '关闭门店', value: 'closing' },
    { label: '关闭门店成功', value: 'close_finished' }
  ]

  // 小店下拉列表
  const storeList = ref<Array<any>>([])
  const getStoreList = async () => {
    if (storeList.value.length === 0) {
      const data = await CommonModel.getStoresDrop()
      storeList.value = data
    }
    return storeList
  }

  // 渠道下拉列表
  const supplierChannelList = ref<Array<any>>([])
  const getSupplierChannelList = async () => {
    if (supplierChannelList.value.length === 0) {
      const data = await CommonModel.getSupplierList()
      supplierChannelList.value = data
    }
    return supplierChannelList
  }

  // 发货时效
  const deliveryTimeList = [
    {
      label: '全部',
      value: '1'
    },
    {
      label: '当日',
      value: '2'
    },
    {
      label: '次日',
      value: '3'
    },
    {
      label: '48小时',
      value: '4'
    }
  ]

  const cateDropList = ref<Array<any>>([])
  const getCateDropList = async (query: any = {}) => {
    if (cateDropList.value.length === 0) {
      const data = await CommonModel.getCateDrop(query)
      cateDropList.value = data
    }
    return cateDropList
  }

  // 订单状态
  const orderStatus = [
    {
      label: '全部',
      value: '',
      numKey: 'totalOrderCnt'
    },
    {
      label: '待支付',
      value: '10',
      numKey: 'waitPayCnt'
    },
    {
      label: '待发货',
      value: '20',
      numKey: 'waitSendCnt'
    },
    {
      label: '部分发货',
      value: '21',
      numKey: 'partSendCnt'
    },
    {
      label: '待收货',
      value: '30',
      numKey: 'waitReceiveCnt'
    },
    {
      label: '已完成',
      value: '100',
      numKey: 'completeCnt'
    },
    {
      label: '已取消(售后)',
      value: '200',
      numKey: 'afterSaleCancelCnt'
    },
    {
      label: '已取消',
      value: '250',
      numKey: 'cancelCnt'
    }
  ]

  return {
    orderStatus,
    cateDropList,
    getCateDropList,
    supplierChannelList,
    getSupplierChannelList,
    deliveryTimeList,
    storeList,
    getStoreList,
    storeStausList,
    activeList
  }
})

export default useCommonStore
